package com.citywithincity.db.interfaces;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.Map;

import com.citywithincity.db.ColumnInfo;
import com.citywithincity.db.Entity;

public interface SqlDriver {
	
	
	
	void buildPage(StringBuilder sb,Integer position,Integer pageSize);
	
	String protectTableName(String tableName);
	
	int posToPage(Integer position,Integer pageSize);
	
	PreparedStatement prepareInsert(Connection connection, String sql, String pk) throws SQLException;
	
	Object getAutoIncrease(PreparedStatement ps)  throws SQLException ;
	
	
	IColumnDataValidate createValidate(ColumnInfo columnInfo, ResultSetMetaData data) throws SQLException;
	
	Class<?> getColumnClass(ResultSetMetaData data,int i);


	Class<?> getAutoIncreaseClass();
	
	
	int insert(Connection connection, Object data,Entity<?> entity) throws SQLException;
	
	
	int insertOrUpdate(Select<?> ar,String tableName,String keyName,Map<String, Object> map);
	int insertOrUpdate(Select<?> ar, String tableName, String[] unikeys, Map<String, Object> map);

	IValueConvert create(Class<?> columnClass, Class<?> targetClass);

	/**
	 * 字段名进行保护
	 * @param name
	 * @return
	 */
	String protectColumn(String name);
}
